#include <openssl/core.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/provider.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if defined(_WIN32) || defined(WIN32)
#define LIB_NAME(name) #name
#else
#define LIB_NAME(name) "lib" #name
#endif

static uint8_t iv[16] = {
    0xb0, 0x4d, 0xc4, 0xdd, 0xb6, 0xb9, 0x69, 0x32,
    0x91, 0x2b, 0xdc, 0xac, 0x10, 0x1f, 0xf4, 0x62,
};
static uint8_t user_key[16] = {
    0xc7, 0x10, 0x7d, 0x76, 0x38, 0xd7, 0x08, 0xc8,
    0x2e, 0x94, 0xa4, 0xfc, 0x2d, 0xa4, 0xcc, 0xd8,
};
static uint8_t pt[1024] = {
    0xc4, 0x7b, 0x4e, 0x69, 0x8e, 0x43, 0xa8, 0x91, 0xba, 0x8d, 0x90, 0xa9,
    0x20, 0x61, 0x6c, 0xd1, 0x8d, 0x66, 0xdc, 0xe1, 0xa3, 0x36, 0xb8, 0x5a,
    0x5f, 0x62, 0xaa, 0x49, 0x45, 0x5c, 0x04, 0x97, 0xb3, 0x7d, 0x2c, 0x61,
    0x6b, 0x4c, 0x7d, 0xb2, 0x12, 0x7a, 0xb7, 0xfb, 0xe6, 0x6e, 0x4d, 0x6f,
    0xb3, 0x2a, 0x3a, 0x38, 0x83, 0x37, 0x09, 0x80, 0x01, 0x37, 0x0d, 0x9d,
    0x42, 0x7a, 0xe5, 0xb1, 0x18, 0x9b, 0x75, 0x7c, 0xff, 0x08, 0x6e, 0x67,
    0x22, 0x61, 0x4f, 0x59, 0x8a, 0x57, 0xcf, 0x86, 0xde, 0x32, 0xc0, 0x8c,
    0x96, 0xe6, 0x5d, 0xf4, 0x47, 0x80, 0x02, 0xd9, 0xbe, 0xf5, 0x97, 0xa1,
    0x59, 0x72, 0x3a, 0xea, 0x72, 0xd7, 0x5e, 0xdf, 0x3e, 0xdf, 0x22, 0x5f,
    0x9b, 0xc4, 0x14, 0x44, 0xb4, 0x34, 0xdd, 0xff, 0x7b, 0x8f, 0x16, 0x8a,
    0xa0, 0x53, 0x2b, 0x58, 0x14, 0xa8, 0x02, 0xb6, 0x8a, 0xc2, 0xf7, 0x73,
    0x6f, 0x37, 0xe3, 0x78, 0x3f, 0x68, 0xe7, 0x81, 0xfc, 0xa8, 0x25, 0xc2,
    0x34, 0xe3, 0x5c, 0x98, 0xa4, 0x7a, 0xf3, 0x0b, 0x1d, 0xa8, 0x21, 0xe2,
    0x70, 0xe8, 0x37, 0xcc, 0x15, 0x1e, 0x85, 0x21, 0x49, 0x97, 0x14, 0xec,
    0xef, 0x1c, 0x42, 0x68, 0xc5, 0x64, 0x50, 0x1e, 0x5c, 0x36, 0x75, 0x37,
    0x96, 0x17, 0xdc, 0xc4, 0x0e, 0xd4, 0xf8, 0xda, 0x4b, 0xe7, 0xc0, 0xf7,
    0xc0, 0x12, 0xcd, 0x7c, 0xa6, 0x6d, 0x68, 0xfc, 0xf3, 0xfb, 0x2b, 0xbe,
    0x03, 0xc7, 0x70, 0x17, 0xb3, 0x9d, 0x5d, 0x2c, 0x92, 0xd0, 0xb8, 0x36,
    0x85, 0xf4, 0x6c, 0x04, 0x29, 0x5c, 0x02, 0x68, 0x70, 0x93, 0x8a, 0x4d,
    0x4a, 0x3d, 0xe5, 0x35, 0xc8, 0x22, 0x63, 0x2c, 0x67, 0x84, 0xc3, 0x3e,
    0x7b, 0x5f, 0x90, 0x9d, 0x1d, 0xf6, 0xa4, 0xc5, 0x7f, 0xd7, 0xc4, 0x25,
    0x06, 0x0a, 0x9f, 0x22, 0x90, 0x42, 0xec, 0xa3, 0x1e, 0xde, 0xe9, 0x1c,
    0xe6, 0x47, 0x70, 0x3e, 0xaa, 0x09, 0x23, 0x80, 0xa0, 0xba, 0x84, 0x1c,
    0x9b, 0xa8, 0x08, 0x5a, 0x43, 0x36, 0xe7, 0x84, 0x00, 0x52, 0x04, 0x9e,
    0x84, 0x91, 0x73, 0x2a, 0x5a, 0x2d, 0x17, 0x4b, 0x83, 0xc1, 0x40, 0xe0,
    0xd4, 0x53, 0x49, 0xf6, 0xe5, 0x85, 0x2a, 0x91, 0xbb, 0x17, 0xe6, 0xc4,
    0x31, 0x78, 0x14, 0xe4, 0x89, 0x47, 0x09, 0x3b, 0x6e, 0x37, 0xf7, 0x67,
    0x10, 0xd3, 0xba, 0xc6, 0xf8, 0x9b, 0xaa, 0x20, 0xe3, 0x51, 0xb9, 0x5c,
    0xbd, 0xef, 0xc5, 0xcc, 0x74, 0x65, 0x1b, 0x2e, 0x38, 0x27, 0x2e, 0x12,
    0x4a, 0xfe, 0x55, 0xf0, 0x35, 0xd9, 0xcc, 0x5f, 0x1f, 0xf0, 0xc9, 0xcb,
    0x1a, 0x33, 0x99, 0x2d, 0x3c, 0xd5, 0x12, 0xfc, 0x76, 0xa8, 0x64, 0xe6,
    0xaa, 0xe1, 0x94, 0x81, 0x75, 0x47, 0x17, 0xd7, 0x27, 0x70, 0x9f, 0xb3,
    0xdd, 0x7f, 0x10, 0x13, 0x2f, 0xc2, 0x4a, 0xe2, 0xa8, 0x4d, 0xb7, 0xab,
    0xcb, 0x22, 0x9e, 0xca, 0x98, 0xb5, 0x62, 0x1d, 0x5d, 0xd8, 0x01, 0x3b,
    0x6c, 0x7b, 0xf0, 0x3d, 0x8b, 0xde, 0xb3, 0xed, 0x19, 0x5f, 0x08, 0xfd,
    0x3c, 0x44, 0x74, 0x7e, 0xb7, 0x58, 0x1c, 0xec, 0xe0, 0x8b, 0xbe, 0x6d,
    0x75, 0x8b, 0x66, 0x9a, 0x43, 0x24, 0x2b, 0x7f, 0x08, 0x53, 0xbd, 0xad,
    0xbc, 0x50, 0x13, 0x59, 0x0b, 0xc2, 0xec, 0x8d, 0xce, 0x13, 0xd0, 0xaa,
    0x7f, 0x23, 0xd5, 0x12, 0xc7, 0x2a, 0x2e, 0x42, 0x9e, 0x87, 0x27, 0x5d,
    0xbe, 0x05, 0x6b, 0x28, 0x31, 0xcf, 0x90, 0x40, 0xce, 0x91, 0xa9, 0x10,
    0x61, 0x38, 0x0b, 0xff, 0xef, 0xbe, 0xfc, 0xcc, 0xd0, 0xcf, 0x00, 0x59,
    0x16, 0x9d, 0xb7, 0x03, 0xf7, 0x1e, 0x9d, 0xba, 0xfc, 0x89, 0x39, 0xfa,
    0x0f, 0x30, 0x3e, 0x18, 0x1d, 0x21, 0xa0, 0x9e, 0xf1, 0xb4, 0xb0, 0x57,
    0x19, 0xc9, 0x58, 0xa4, 0x49, 0x2f, 0x43, 0x8a, 0x8f, 0xb3, 0x89, 0x79,
    0xd5, 0x6f, 0xca, 0x64, 0x0b, 0x23, 0x91, 0xc9, 0x4c, 0x31, 0x68, 0x5f,
    0xb7, 0x72, 0x7d, 0x10, 0x11, 0x45, 0x2a, 0xc4, 0xc7, 0x80, 0x68, 0x0e,
    0xdf, 0x1b, 0xd8, 0x23, 0xaa, 0xb0, 0x79, 0x1d, 0xd5, 0x80, 0xeb, 0xb6,
    0x4a, 0xee, 0x0e, 0xc5, 0xd1, 0x31, 0x5a, 0xac, 0xf4, 0xc2, 0x28, 0x23,
    0xe6, 0x17, 0x86, 0x55, 0x7f, 0xfd, 0x83, 0x43, 0x53, 0x9b, 0xb4, 0x22,
    0x28, 0xc2, 0x77, 0x82, 0x79, 0x9d, 0xf9, 0xe4, 0x51, 0x3a, 0x05, 0x5d,
    0x0f, 0xa4, 0xf9, 0x72, 0x81, 0x1c, 0xbb, 0x6a, 0xa8, 0xa2, 0x1f, 0xf4,
    0x87, 0xcd, 0x27, 0xb4, 0xb4, 0x3f, 0xeb, 0x18, 0x72, 0xb2, 0xae, 0x14,
    0x3c, 0x68, 0x08, 0x22, 0xdc, 0x25, 0x48, 0x16, 0x5a, 0xdb, 0x32, 0x50,
    0xd4, 0x84, 0x9c, 0x7f, 0x50, 0xe8, 0xe7, 0x68, 0x74, 0xc3, 0x15, 0x77,
    0x96, 0x25, 0x74, 0xa3, 0xcd, 0xab, 0xce, 0xdb, 0x50, 0xe0, 0x4d, 0x5e,
    0xd2, 0xf0, 0x78, 0x77, 0x21, 0xbe, 0xb4, 0xca, 0xd3, 0x8e, 0xd4, 0x6b,
    0x2b, 0x2e, 0xd0, 0xd8, 0xfb, 0x75, 0x56, 0xe2, 0x97, 0xf1, 0xd3, 0xda,
    0x29, 0xdb, 0x02, 0x2f, 0x94, 0x3a, 0x53, 0x3a, 0xce, 0x9e, 0x85, 0x4a,
    0x23, 0xd6, 0x5f, 0x01, 0x8b, 0x61, 0x81, 0x75, 0x0e, 0x5f, 0x31, 0xcc,
    0xbd, 0xe9, 0xdc, 0x3d, 0xe3, 0xf9, 0x94, 0xbb, 0x3a, 0x54, 0x5b, 0xb6,
    0x56, 0x6c, 0x95, 0xea, 0x5f, 0x80, 0x6e, 0xc6, 0xb9, 0xaa, 0x1c, 0x82,
    0x29, 0xa3, 0xee, 0xf9, 0x6e, 0x8e, 0xc4, 0x7d, 0x9c, 0xd4, 0x1b, 0xd4,
    0x85, 0xf2, 0x7e, 0xea, 0x35, 0x19, 0x4c, 0xa4, 0x8c, 0xc9, 0x77, 0x9b,
    0xf4, 0x4a, 0x7c, 0xa4, 0xfa, 0x23, 0x06, 0x2d, 0xee, 0x57, 0x8e, 0x43,
    0xbb, 0xcf, 0x41, 0x5a, 0x49, 0xfe, 0x9b, 0x10, 0xd1, 0x54, 0x91, 0xbf,
    0x02, 0xaa, 0x21, 0x7d, 0x0f, 0x3d, 0x36, 0xcb, 0xe9, 0xb0, 0xb5, 0x55,
    0xfa, 0xaf, 0xa8, 0x65, 0xb5, 0x42, 0x00, 0xbd, 0x94, 0x12, 0x85, 0x91,
    0x9f, 0xab, 0xa0, 0xca, 0xf1, 0xc2, 0xb7, 0x22, 0x83, 0xfa, 0x6a, 0x4a,
    0xd6, 0x47, 0xb9, 0x96, 0x8f, 0xda, 0xde, 0xe2, 0x77, 0x93, 0x4c, 0x26,
    0x80, 0x34, 0x76, 0xc7, 0x73, 0xeb, 0x88, 0x74, 0x95, 0xc2, 0xa0, 0x88,
    0x76, 0xdb, 0xa2, 0x16, 0xb9, 0x99, 0x3b, 0x39, 0x78, 0xfd, 0x3d, 0xb1,
    0xb0, 0x67, 0x47, 0x49, 0x66, 0x94, 0x6a, 0x97, 0xf9, 0x40, 0xd5, 0xf2,
    0x3a, 0xf3, 0x8a, 0xc6, 0x21, 0xd2, 0x7f, 0x55, 0xda, 0x6a, 0x6a, 0x6f,
    0x03, 0x82, 0x47, 0x91, 0x54, 0x37, 0x16, 0xbf, 0x88, 0x63, 0x73, 0x9a,
    0x2c, 0x2a, 0xd8, 0xdb, 0x04, 0x02, 0xed, 0x9d, 0x4d, 0xb7, 0xe0, 0x8a,
    0x74, 0xed, 0x7a, 0xd0, 0xa2, 0xea, 0x5b, 0x69, 0xda, 0xda, 0x58, 0x0b,
    0xdf, 0x86, 0x9a, 0x7d, 0x40, 0xf2, 0x0e, 0x33, 0x1a, 0x56, 0x6b, 0x64,
    0x16, 0xb5, 0x34, 0x3a, 0xe7, 0xbb, 0x6d, 0xeb, 0x75, 0xad, 0x2d, 0x62,
    0x25, 0x49, 0xd2, 0x12, 0xf0, 0x7b, 0x95, 0xe0, 0x7f, 0x86, 0xbd, 0xe6,
    0x14, 0xe5, 0xa5, 0xbf, 0xd8, 0x4d, 0xce, 0x3f, 0x8d, 0x35, 0xe6, 0xf9,
    0x7f, 0xbc, 0xf9, 0xdd, 0x9d, 0xd3, 0xa6, 0xc5, 0x22, 0x33, 0xf4, 0x77,
    0xba, 0xb4, 0x36, 0xdc, 0xe4, 0x87, 0x01, 0x64, 0x03, 0x88, 0x89, 0x69,
    0xa7, 0x95, 0xb5, 0xb0, 0x12, 0xe4, 0x79, 0x4f, 0x6f, 0x2f, 0xe3, 0xda,
    0x3f, 0x9e, 0xef, 0x62, 0x2c, 0x94, 0x9c, 0x58, 0x1b, 0x5b, 0xdc, 0xdc,
    0x03, 0xc6, 0x78, 0x98, 0x44, 0x85, 0x23, 0xc1, 0x25, 0x3d, 0x62, 0x5d,
    0x69, 0x84, 0xc1, 0x8e,
};
static uint8_t ct[1024] = {
    0x15, 0x87, 0xfc, 0x99, 0x19, 0x64, 0x0f, 0x42, 0xcb, 0x3c, 0xa7, 0xd2,
    0x42, 0x44, 0x84, 0xa1, 0x30, 0x04, 0x25, 0x30, 0xfd, 0xf0, 0x48, 0x50,
    0x4a, 0xf3, 0xe1, 0x52, 0xcd, 0x66, 0x44, 0xeb, 0x2b, 0x48, 0x96, 0xf8,
    0x67, 0x6f, 0x85, 0x5e, 0x8f, 0x05, 0x23, 0x0b, 0x81, 0xde, 0xfe, 0x5b,
    0x08, 0x85, 0x0f, 0x61, 0x2f, 0x2f, 0x33, 0x28, 0x4e, 0x1d, 0xb1, 0x88,
    0x60, 0x15, 0x53, 0x2b, 0xc4, 0x07, 0xbc, 0xf2, 0x56, 0x60, 0x94, 0xc8,
    0x2a, 0x65, 0x39, 0xbf, 0xc2, 0x2b, 0x7e, 0xf7, 0x32, 0x83, 0x0e, 0xb6,
    0x70, 0xcb, 0xf8, 0x2b, 0xed, 0xc4, 0xfb, 0xe4, 0x3a, 0x43, 0x4a, 0x76,
    0xcb, 0x58, 0xc0, 0xbe, 0xf9, 0xf8, 0xa9, 0x0b, 0x8f, 0x21, 0x9e, 0xe6,
    0xc1, 0x02, 0xae, 0x35, 0xee, 0x84, 0x37, 0xaf, 0x6e, 0x80, 0x6c, 0x0a,
    0x08, 0x70, 0x68, 0x49, 0x33, 0xe2, 0x2a, 0x63, 0xf1, 0x5e, 0x23, 0xa6,
    0x24, 0xae, 0x68, 0xb1, 0xb6, 0x46, 0x7f, 0xdf, 0x20, 0x04, 0x1c, 0x58,
    0x80, 0x7b, 0xd1, 0xed, 0x2a, 0xbf, 0x28, 0xeb, 0x78, 0x39, 0x2d, 0x72,
    0x20, 0xb6, 0xf6, 0xf4, 0xb2, 0xd8, 0xda, 0x53, 0xeb, 0x28, 0x4e, 0x67,
    0x04, 0x35, 0x13, 0xd9, 0xc3, 0xff, 0x32, 0x1f, 0x6b, 0xfc, 0x31, 0xc0,
    0x45, 0x80, 0xb2, 0x25, 0x64, 0x25, 0xf9, 0x89, 0x75, 0x56, 0xd3, 0x0a,
    0xe6, 0xc7, 0x30, 0x7b, 0x88, 0xe4, 0x5e, 0x36, 0x2b, 0x24, 0x66, 0xc9,
    0x45, 0xec, 0x20, 0x40, 0x10, 0xe2, 0x10, 0x6e, 0x8a, 0x96, 0xb1, 0xe1,
    0x41, 0x1f, 0x54, 0x3f, 0x9b, 0xc8, 0x4d, 0x93, 0xeb, 0xb0, 0x9c, 0xb5,
    0xc4, 0x76, 0x5c, 0x50, 0x8e, 0xc8, 0x6a, 0x10, 0x37, 0x20, 0x93, 0x3a,
    0x27, 0xe0, 0x88, 0xa4, 0x0e, 0xb4, 0x0e, 0xda, 0x10, 0x4d, 0xb5, 0x6a,
    0xb8, 0xfe, 0xd2, 0x7d, 0x9a, 0x81, 0xd5, 0x12, 0x65, 0x06, 0x20, 0x6b,
    0x7d, 0xd8, 0xa4, 0x1d, 0xdb, 0x9d, 0x69, 0x35, 0xc2, 0xa9, 0xa0, 0xf4,
    0xcd, 0x10, 0xd5, 0x33, 0xf1, 0x57, 0xe3, 0xc4, 0xb6, 0x9a, 0xc3, 0x97,
    0xf7, 0x67, 0x95, 0x62, 0x78, 0x96, 0x51, 0x5d, 0xb8, 0xc4, 0x58, 0x7e,
    0x8c, 0x9a, 0xe8, 0x12, 0x94, 0x7b, 0x09, 0xf3, 0xba, 0xb6, 0x13, 0x12,
    0x5c, 0x6b, 0x41, 0x5c, 0x97, 0x5a, 0xe0, 0x9f, 0xd6, 0x01, 0xcd, 0xe1,
    0xcf, 0xa8, 0xab, 0xda, 0x59, 0x8f, 0x74, 0xf4, 0x20, 0x6d, 0x3b, 0x03,
    0xa3, 0x4a, 0x32, 0x78, 0xee, 0x24, 0xa0, 0xc0, 0x71, 0x13, 0x3a, 0x41,
    0xf3, 0xb5, 0x06, 0x8a, 0xcf, 0xcc, 0x6a, 0xb3, 0xed, 0x3d, 0x95, 0x99,
    0xc8, 0x8e, 0xdf, 0x46, 0xc0, 0x23, 0x1e, 0x42, 0xf2, 0x36, 0x39, 0x79,
    0x26, 0x7e, 0xb4, 0x58, 0x44, 0xaa, 0x4f, 0x3d, 0x5f, 0x0d, 0xc7, 0x73,
    0x6d, 0xd2, 0x0b, 0xae, 0x83, 0x13, 0xc6, 0x43, 0x45, 0x56, 0x43, 0x22,
    0xb8, 0xb8, 0x02, 0xf7, 0x64, 0x20, 0x90, 0x32, 0x1c, 0x48, 0xb3, 0xe6,
    0xfd, 0x4d, 0x68, 0x01, 0x68, 0xb9, 0x80, 0x82, 0xaa, 0x40, 0x7a, 0xc1,
    0x12, 0x4d, 0x68, 0xe2, 0x3e, 0xbf, 0x0d, 0x08, 0x1f, 0xb3, 0x42, 0xec,
    0xd6, 0xf9, 0xfa, 0x94, 0x27, 0x3a, 0x87, 0x30, 0x21, 0xba, 0xac, 0x40,
    0x92, 0xc2, 0x49, 0xcc, 0xa5, 0xeb, 0x28, 0x7e, 0xfb, 0x08, 0x68, 0x9a,
    0x61, 0x27, 0xd0, 0x18, 0x1a, 0x8e, 0x75, 0x86, 0xa1, 0xe5, 0x86, 0xbd,
    0x68, 0xb7, 0x6c, 0x84, 0xf1, 0x6a, 0x47, 0x16, 0xd8, 0x20, 0x52, 0x58,
    0x1c, 0xea, 0x9c, 0xb9, 0x66, 0x73, 0xcc, 0xce, 0x51, 0xc3, 0x1e, 0xb2,
    0x96, 0xe6, 0x27, 0x8a, 0xb9, 0xdb, 0x24, 0x37, 0x6a, 0x81, 0x7f, 0x0d,
    0xcd, 0x45, 0x27, 0x1f, 0xdf, 0x13, 0xca, 0x14, 0x12, 0xaf, 0x31, 0xbe,
    0x22, 0xe3, 0x3f, 0x09, 0xf0, 0xe1, 0xdb, 0x42, 0xdc, 0x82, 0xce, 0xaa,
    0x8d, 0x0d, 0x5a, 0xe8, 0xce, 0x06, 0xed, 0x51, 0xca, 0xda, 0x46, 0x30,
    0x27, 0xd4, 0x98, 0x77, 0x73, 0x38, 0xff, 0xfd, 0x4a, 0x41, 0x2d, 0x27,
    0x85, 0xa9, 0x70, 0x6b, 0x93, 0xac, 0x4d, 0x9b, 0xdb, 0xe9, 0xd8, 0x51,
    0x63, 0x67, 0xce, 0x92, 0x27, 0xc6, 0x32, 0x46, 0x40, 0x13, 0x4f, 0x25,
    0x69, 0x8b, 0xd8, 0x54, 0x55, 0x99, 0x85, 0xe5, 0xb7, 0x04, 0xf0, 0xcb,
    0x05, 0x32, 0x91, 0x3c, 0xb4, 0x9c, 0xaa, 0x9b, 0xd9, 0x33, 0x7a, 0x68,
    0x95, 0x04, 0x29, 0xc8, 0x24, 0xc1, 0xaf, 0x86, 0x7c, 0x41, 0x32, 0x82,
    0xb2, 0xaf, 0x6e, 0x65, 0x72, 0x6a, 0x7e, 0x67, 0xb1, 0xa3, 0x4a, 0xf9,
    0x2b, 0xf2, 0x35, 0x43, 0xb4, 0x19, 0x7e, 0xb2, 0x7e, 0x00, 0x1e, 0x74,
    0x2d, 0x92, 0xd0, 0x59, 0x6b, 0x86, 0x6a, 0x99, 0x2b, 0x1e, 0x9b, 0xfd,
    0xf0, 0xb3, 0x7d, 0xe8, 0x49, 0x63, 0x5c, 0x4e, 0xaf, 0xdd, 0x75, 0x30,
    0x65, 0xd7, 0x91, 0xd6, 0x6d, 0xcc, 0x27, 0x82, 0xe7, 0x12, 0xc8, 0x8a,
    0x94, 0x98, 0x1c, 0x24, 0x38, 0xb2, 0x51, 0x51, 0x39, 0x84, 0xf2, 0x1b,
    0x83, 0xea, 0x53, 0x3f, 0xf7, 0x78, 0xb7, 0xa9, 0x9e, 0x78, 0xe1, 0x1c,
    0xf7, 0x76, 0x41, 0x98, 0x7c, 0x51, 0xe6, 0x4a, 0x6c, 0xb7, 0x47, 0x17,
    0x43, 0x1f, 0x20, 0x91, 0x32, 0xa7, 0xdb, 0x0d, 0xc7, 0x1c, 0x49, 0x33,
    0xfa, 0x09, 0x62, 0x85, 0x58, 0xae, 0xb0, 0x01, 0x1d, 0x1d, 0x53, 0x25,
    0xed, 0x98, 0xab, 0x50, 0x92, 0x51, 0x1a, 0x2d, 0x20, 0x8a, 0xc8, 0xfd,
    0x0e, 0x48, 0x2a, 0x1a, 0xe9, 0x78, 0x06, 0x00, 0x85, 0xef, 0x95, 0x14,
    0x80, 0x20, 0x26, 0x46, 0x52, 0x53, 0x2a, 0xdb, 0xfd, 0x60, 0x8a, 0xcd,
    0x14, 0x01, 0x90, 0x89, 0xd5, 0x00, 0x8e, 0xba, 0x5a, 0x14, 0xef, 0xdd,
    0x5c, 0x01, 0x76, 0x14, 0xe3, 0xd6, 0xd6, 0x7d, 0x3d, 0x6f, 0xb0, 0x83,
    0x48, 0xb8, 0xfb, 0xcc, 0x30, 0x76, 0x2c, 0xf1, 0x25, 0xa2, 0x33, 0xd1,
    0x98, 0x62, 0x1b, 0x14, 0xb8, 0x47, 0x48, 0x09, 0x06, 0x38, 0x3e, 0x25,
    0x6b, 0xa2, 0x5f, 0x5c, 0xe4, 0xb6, 0xcf, 0x0f, 0x87, 0xc4, 0xa7, 0x3c,
    0x3f, 0xfe, 0x17, 0x23, 0x73, 0x0d, 0x1f, 0xb2, 0xef, 0x11, 0xd4, 0xda,
    0x48, 0x79, 0xab, 0xcb, 0x8e, 0x9e, 0x8a, 0x7f, 0x2e, 0xda, 0x59, 0xeb,
    0xbf, 0xda, 0xbf, 0xb6, 0xca, 0x92, 0x02, 0x21, 0x88, 0x6c, 0x08, 0x14,
    0xf2, 0x06, 0xff, 0xf8, 0xcd, 0x3a, 0xf7, 0x2a, 0x59, 0x9f, 0x24, 0x04,
    0x7d, 0x68, 0xd2, 0x18, 0xe5, 0xb0, 0xcb, 0x0f, 0x29, 0xa1, 0x63, 0x03,
    0x0d, 0xe1, 0xb4, 0x57, 0x08, 0xd2, 0xa9, 0x11, 0x87, 0x91, 0x42, 0x50,
    0xe8, 0xf3, 0xed, 0x44, 0xfd, 0xc6, 0xd6, 0x03, 0xc6, 0x1f, 0x5a, 0xe6,
    0x3b, 0x34, 0x51, 0x2c, 0x39, 0x9e, 0x55, 0x7c, 0xd7, 0x90, 0x16, 0x4d,
    0xbf, 0x9f, 0x2b, 0x13, 0x21, 0x35, 0xd7, 0xb2, 0x06, 0xef, 0xf7, 0xa8,
    0x4b, 0x77, 0xbf, 0x0b, 0x3f, 0x76, 0x33, 0x50, 0xc8, 0x41, 0xd6, 0xee,
    0x51, 0xdc, 0x10, 0x37, 0x9a, 0x93, 0xae, 0x43, 0xa2, 0xc4, 0x79, 0xc9,
    0x2d, 0x3f, 0xbc, 0xf5, 0x94, 0xbf, 0x5d, 0x2e, 0xcb, 0x76, 0xa4, 0x6f,
    0x3c, 0xf9, 0x8c, 0x47, 0x58, 0x48, 0xbc, 0xbd, 0x40, 0x91, 0x4d, 0xc5,
    0x1c, 0xbc, 0xfd, 0x20, 0x0b, 0xa5, 0xd6, 0x05, 0xe1, 0x85, 0xc1, 0x9c,
    0x72, 0x43, 0xaf, 0x6e, 0xa4, 0xc8, 0x28, 0x57, 0x03, 0xd5, 0x78, 0x70,
    0x12, 0xef, 0xe0, 0xf1, 0x66, 0x3a, 0x3c, 0xda, 0x71, 0x09, 0x5c, 0x40,
    0x9b, 0x42, 0xc3, 0x0b,
};

#define PRINT(fmt, ...) \
    printf("[LOG] " fmt " %s:%d\n", ##__VA_ARGS__, __FILE__, __LINE__)

int main()
{
    static uint8_t  buffer[1024 * 1024];
    int             ret;
    EVP_CIPHER*     cipher = NULL;
    EVP_CIPHER_CTX* cctx   = NULL;
    OSSL_PROVIDER*  prov   = NULL;
    uint8_t*        out    = buffer;
    int             outl   = 0;

    // set search path
    ret = OSSL_PROVIDER_set_default_search_path(NULL, "./");
    if (!ret)
    {
        PRINT("Failed to set default search path");
        PRINT("%s", ERR_error_string(ERR_get_error(), NULL));
        exit(0);
    }
    prov = OSSL_PROVIDER_load(NULL, LIB_NAME(gmlibprov));
    if (prov == NULL)
    {
        PRINT("OSSL_PROVIDER_load failed");
        PRINT("%s", ERR_error_string(ERR_get_error(), NULL));
        exit(0);
    }

    printf("[%d] Provider loaded\n", __LINE__);

    // fetch cipher
    cipher = EVP_CIPHER_fetch(NULL, "SM4-CBC", "provider=gmlibprov");
    if (cipher == NULL)
    {
        PRINT("EVP_CIPHER_fetch failed");
        PRINT("%s", ERR_error_string(ERR_get_error(), NULL));
        exit(0);
    }
    cctx = EVP_CIPHER_CTX_new();

    printf("[%d] EVP Cipher SM4 CBC start\n", __LINE__);

    // TEST ENCRYPT
    {
        ret = EVP_CipherInit(cctx, cipher, user_key, iv, 1);
        if (!ret)
        {
            PRINT("EVP_CipherInit failed");
            PRINT("%s", ERR_error_string(ERR_get_error(), NULL));
            exit(0);
        }

        out  = buffer;
        outl = 0;

        ret = EVP_CipherUpdate(cctx, out, &outl, pt, sizeof(pt));
        if (!ret)
        {
            PRINT("EVP_CipherUpdate failed");
            PRINT("%s", ERR_error_string(ERR_get_error(), NULL));
            exit(0);
        }
        out += outl;

        ret = EVP_CipherFinal(cctx, out, &outl);
        if (!ret)
        {
            PRINT("EVP_CipherFinal failed");
            PRINT("%s", ERR_error_string(ERR_get_error(), NULL));
            exit(0);
        }
        out += outl;

        if ((size_t)out - (size_t)buffer != sizeof(ct))
        {
            PRINT("EVP_CipherFinal failed");
            exit(0);
        }
        if (memcmp(ct, buffer, sizeof(ct)) != 0)
        {
            PRINT("EVP_CipherFinal failed");
            exit(0);
        }
    }

    // TEST DECRYPT
    {
        ret = EVP_CipherInit(cctx, cipher, user_key, iv, 0);
        if (!ret)
        {
            PRINT("EVP_CipherInit failed");
            PRINT("%s", ERR_error_string(ERR_get_error(), NULL));
            exit(0);
        }

        out  = buffer;
        outl = 0;

        ret = EVP_CipherUpdate(cctx, out, &outl, ct, sizeof(ct));
        if (!ret)
        {
            PRINT("EVP_CipherUpdate failed");
            PRINT("%s", ERR_error_string(ERR_get_error(), NULL));
            exit(0);
        }
        out += outl;

        ret = EVP_CipherFinal(cctx, out, &outl);
        if (!ret)
        {
            PRINT("EVP_CipherFinal failed");
            PRINT("%s", ERR_error_string(ERR_get_error(), NULL));
            exit(0);
        }
        out += outl;

        if ((size_t)out - (size_t)buffer != sizeof(pt))
        {
            PRINT("EVP_CipherFinal failed");
            exit(0);
        }
        if (memcmp(pt, buffer, sizeof(pt)) != 0)
        {
            PRINT("EVP_CipherFinal failed");
            exit(0);
        }
    }

    EVP_CIPHER_CTX_free(cctx);
    EVP_CIPHER_free(cipher);
    OSSL_PROVIDER_unload(prov);

    printf("[%d] EVP CIPHER SM4 CBC PASS\n", __LINE__);

    return 0;
}